package com.ruoyi.hcmain.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.hcmain.domain.HcPrich;
import com.ruoyi.hcmain.domain.HcStuff;
import com.ruoyi.hcmain.mapper.HcPrichMapper;
import com.ruoyi.hcmain.mapper.HcStuffMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.hcmain.mapper.HcDispatchMapper;
import com.ruoyi.hcmain.domain.HcDispatch;
import com.ruoyi.hcmain.service.IHcDispatchService;

/**
 * 出库列Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-08-15
 */
@Service
public class HcDispatchServiceImpl implements IHcDispatchService 
{
    @Autowired
    private HcDispatchMapper hcDispatchMapper;
    @Autowired
    private HcStuffMapper hcStuffMapper;

    @Autowired
    private HcPrichMapper hcPrichMapper;

    /**
     * 查询出库列
     * 
     * @param id 出库列主键
     * @return 出库列
     */
    @Override
    public HcDispatch selectHcDispatchById(Long id)
    {
        return hcDispatchMapper.selectHcDispatchById(id);
    }

    /**
     * 查询出库列列表
     * 
     * @param hcDispatch 出库列
     * @return 出库列
     */
    @Override
    public List<HcDispatch> selectHcDispatchList(HcDispatch hcDispatch)
    {
        return hcDispatchMapper.selectHcDispatchList(hcDispatch);
    }
    @Override
    public List<HcDispatch> selectHcDispatchByCreateTime(HcDispatch hcDispatch)
    {
        return hcDispatchMapper.selectHcDispatchByCreateTime(hcDispatch);
    }

    /**
     * 新增出库列
     * 
     * @param hcDispatch 出库列
     * @return 结果
     */
    @Override
    public int insertHcDispatch(HcDispatch hcDispatch)
    {
        try {
            //查询当前价格和信息
            HcStuff hcStuff=hcStuffMapper.selectHcStuffByStuffId(hcDispatch.getStuffId());
            HcPrich hcPrich=hcPrichMapper.selectHcPrichByStuffId(hcDispatch.getStuffId());
            hcStuff.setCounts(hcStuff.getCounts()-hcDispatch.getCounts());
            hcDispatch.setPrices(hcPrich.getPrice());
            hcDispatch.setCreateTime(DateUtils.getNowDate());
            hcStuffMapper.updateHcStuff(hcStuff);
            return hcDispatchMapper.insertHcDispatch(hcDispatch);
        }catch (Exception e){

        }
       return 0;
    }

    /**
     * 修改出库列
     * 
     * @param hcDispatch 出库列
     * @return 结果
     */
    @Override
    public int updateHcDispatch(HcDispatch hcDispatch)
    {
        return hcDispatchMapper.updateHcDispatch(hcDispatch);
    }

    /**
     * 批量删除出库列
     * 
     * @param ids 需要删除的出库列主键
     * @return 结果
     */
    @Override
    public int deleteHcDispatchByIds(Long[] ids)
    {
        return hcDispatchMapper.deleteHcDispatchByIds(ids);
    }

    /**
     * 删除出库列信息
     * 
     * @param id 出库列主键
     * @return 结果
     */
    @Override
    public int deleteHcDispatchById(Long id)
    {
        return hcDispatchMapper.deleteHcDispatchById(id);
    }
}
